using UnityEngine;
using System.Collections;



public class FlipPanel : MonoBehaviour {
	
	ConfigurableJoint configurableJoint;
	bool buttonPressed = false;
	
	Quaternion pressedRotation;
	Quaternion unpressedRotation;
	
	// Use this for initialization
	void Start () {
		configurableJoint = gameObject.GetComponent( typeof(ConfigurableJoint) ) as ConfigurableJoint;
		
		pressedRotation = new Quaternion(0,0,-1,1);
		unpressedRotation = new Quaternion(0,0,0,1);
	}
	
	// Update is called once per frame
	void Update () {
		
		if(Input.GetMouseButton(0))
		{
			buttonPressed = true;
		}
		else
		{
			buttonPressed = false;
		}
	}
	
	// Fixe update
	void FixedUpdate()
	{
		// Apply physics here
		if(buttonPressed)
		{
			ReachPressedPosition();
		}
		else
		{
			ReachUnPressedPosition();
		}
	}
	
	void ReachPressedPosition()
	{
		configurableJoint.targetRotation = pressedRotation;
	}
	
	void ReachUnPressedPosition()
	{
		configurableJoint.targetRotation = unpressedRotation;
	}
}
